/**
 * 
 */
package actions;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import com.alibaba.fastjson.JSON;
import common.quickvalid.AbstractValidationInterceptor;

/**
 * @data 2012-7-18 下午06:03:47
 * @author nassir wen
 */
@SuppressWarnings("serial")
public class JsonOutputInterceptor extends AbstractValidationInterceptor{

    @Override
    public String errorOutput(String input) {
        // json 格式输出
        Map<String, List<String>> errors = getFieldErrors();
        String text = JSON.toJSONString(errors);
        writeAjaxResult(text);
        return input;
    }
    
    protected void writeAjaxResult(String s) {
        try {
            HttpServletResponse response = ServletActionContext.getResponse();
            response.getOutputStream().write(s.getBytes("utf-8"));
        } catch (Exception e) {
        }
    }
}
